<template>
  <div class="articles-page" ref="scrollContainer">
    <!-- 顶部导航栏 -->
    <header class="page-header">
      <div class="header-container">
        <div class="nav-tabs">
          <div class="nav-tab" :class="{ active: filterType === 'recommended' }" @click="handleFilterChange('recommended')">
            <div class="tab-content">
              <span class="tab-icon">⭐</span>
              <span class="tab-text">推荐</span>
            </div>
          </div>
          <div class="nav-tab" :class="{ active: filterType === 'latest' }" @click="handleFilterChange('latest')">
            <div class="tab-content">
              <span class="tab-icon">🆕</span>
              <span class="tab-text">最新</span>
            </div>
          </div>
          <div class="nav-tab" :class="{ active: filterType === 'popular' }" @click="handleFilterChange('popular')">
            <div class="tab-content">
              <span class="tab-icon">🔥</span>
              <span class="tab-text">热榜</span>
            </div>
          </div>
        </div>

        <div class="header-actions">
          <a-button type="primary" @click="handleWriteArticle" :icon="h(EditOutlined)" class="write-btn">
            <span class="write-text">写文章</span>
          </a-button>
        </div>
      </div>
    </header>

    <div class="page-content">
      <div class="content-container">
        <!-- 侧边筛选栏 -->
        <aside class="sidebar">
          <div class="filter-card">
            <div class="filter-section">
              <h4>搜索</h4>
              <a-input-search v-model:value="searchKeyword" placeholder="搜索文章..." @search="handleSearch" :allow-clear="true" class="custom-search-input" size="large" />
              <!-- <div class="search-container"></div> -->
            </div>
            <div class="filter-section">
              <div class="filter-section-header">
                <h4>分类筛选</h4>
                <a-button v-if="selectedCategory" type="link" size="small" @click="handleCategoryChange(null)" class="clear-btn">清除</a-button>
              </div>
              <div class="category-filters filter-scroll">
                <div class="filter-item" :class="{ active: !selectedCategory }" @click="handleCategoryChange(null)">
                  <span class="filter-icon">📚</span>
                  <span class="filter-text">全部</span>
                </div>
                <div v-for="category in categories" :key="category.id" class="filter-item" @click="handleCategoryChange(category.name)" :class="{ active: selectedCategory === category.name }">
                  <span class="category-name">
                    <span class="filter-icon">📁</span>
                    <span class="filter-text">{{ category.name }}</span>
                    <span class="count">({{ category.article_count }})</span>
                  </span>
                  <a-button v-if="hasAdminPermission && category.article_count === 0" type="text" danger size="small" :icon="h(DeleteOutlined)" @click.stop="handleDeleteCategory(category)" title="删除分类" class="delete-category-btn" />
                </div>
              </div>
            </div>
          </div>
        </aside>

        <!-- 主内容区 -->
        <main class="main-content">
          <!-- 骨架屏加载状态 -->
          <template v-if="loading">
            <div class="skeleton-list">
              <a-skeleton v-for="n in 7" :key="n" :loading="true" active :title="{ width: '60%' }" :paragraph="{ rows: 3, width: ['90%', '80%', '70%'] }" />
            </div>
          </template>

          <template v-else>
            <!-- 空状态 -->
            <div v-if="articles.length === 0" class="empty-state">
              <div class="empty-illustration">
                <file-text-outlined />
              </div>
              <h3>暂无文章</h3>
              <p>{{ getEmptyStateText() }}</p>
              <a-button type="primary" @click="handleWriteArticle" v-if="userStore.isAuthenticated"> 发表第一篇文章 </a-button>
            </div>

            <!-- 文章列表 -->
            <div v-else class="article-list">
              <article v-for="article in articles" :key="article.id" class="article-item" @click="handleArticleClick(article.id)">
                <!-- 文章主要内容 -->
                <div class="article-main">
                  <!-- 文章标题 -->
                  <h2 class="article-title">
                    <span v-if="article.is_recommended" class="recommend-badge">推荐</span>
                    {{ article.title }}
                  </h2>

                  <!-- 文章摘要 -->
                  <div class="article-abstract">
                    {{ article.summary || '暂无摘要' }}
                  </div>

                  <!-- 标签 -->
                  <div class="article-tags" v-if="article.tags && article.tags.length > 0">
                    <a-tag v-for="tag in article.tags.slice(0, 3)" :key="tag" size="small" class="article-tag">
                      {{ tag }}
                    </a-tag>
                    <span v-if="article.tags.length > 3" class="more-tags"> +{{ article.tags.length - 3 }} </span>
                  </div>

                  <!-- 文章元信息 -->
                  <div class="article-meta">
                    <div class="author-info">
                      <AuthorHover :authorId="article.author_id" :authorName="article.author_name" :authorAvatar="article.author_avatar" :size="25" />
                      <span class="author-name">{{ article.author_name }}</span>

                      <div class="article-stats">
                        <span class="stat-item" title="阅读量">
                          <eye-outlined />
                          {{ formatNumber(article.view_count) }}
                        </span>
                        <span class="stat-item" title="点赞数">
                          <like-outlined />
                          {{ formatNumber(article.like_count) }}
                        </span>
                        <span class="stat-item" title="评论数">
                          <message-outlined />
                          {{ formatNumber(article.comment_count) }}
                        </span>
                      </div>
                    </div>
                    <time class="article-time">
                      {{ article.created_at }}
                    </time>
                  </div>
                </div>

                <!-- 文章封面 -->
                <div class="article-cover" v-if="article.cover_image">
                  <img :src="getImageUrl(article.cover_image)" :alt="article.title" />
                </div>
              </article>
            </div>

            <!-- 加载更多状态 -->
            <div class="load-more-status" v-if="articles.length > 0">
              <div v-if="loadingMore" class="loading-more">
                <a-spin size="small" />
                <span>加载中...</span>
              </div>
              <div v-else-if="!pagination.hasNext" class="no-more">
                <span>没有更多文章了</span>
                <div class="total-info">共 {{ pagination.total }} 篇文章</div>
              </div>
            </div>
          </template>
        </main>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, onBeforeUnmount, h, computed, nextTick } from 'vue'
import { useRouter } from 'vue-router'
import { message, Modal } from 'ant-design-vue'
import { EditOutlined, EyeOutlined, LikeOutlined, MessageOutlined, FileTextOutlined, DeleteOutlined } from '@ant-design/icons-vue'
import { useUserStore } from '@/stores/user'
import { getImageUrl } from '@/utils/image'
import { getToken } from '@/utils/auth'
import AuthorHover from '@/components/AuthorHover.vue'
import { API_BASE_URL } from '@/utils/api'

const router = useRouter()
const userStore = useUserStore()

// 管理员权限控制
const ALLOWED_USERNAME = 'woaichitudouo'
const hasAdminPermission = computed(() => {
  return userStore.isAuthenticated && userStore.username === ALLOWED_USERNAME
})

// 响应式数据
const loading = ref(false)
const loadingMore = ref(false)
const articles = ref([])
const categories = ref([])
const filterType = ref('recommended')
const selectedCategory = ref(null)
const searchKeyword = ref('')
const pagination = ref({
  page: 1,
  limit: 15,
  total: 0,
  totalPages: 0,
  hasNext: false
})

// 获取分类列表
const fetchCategories = async () => {
  try {
    const response = await fetch(`${API_BASE_URL}/articles/categories/list`)
    const result = await response.json()

    if (result.code === 200) {
      categories.value = result.data || []
    }
  } catch (error) {
    console.error('获取分类失败:', error)
  }
}

// 获取文章列表
const fetchArticles = async (page = 1, append = false) => {
  if (page === 1) {
    loading.value = true
  } else {
    loadingMore.value = true
  }

  try {
    const params = new URLSearchParams({
      page: page.toString(),
      limit: pagination.value.limit.toString(),
      type: filterType.value
    })

    if (selectedCategory.value) {
      params.append('category', selectedCategory.value)
    }

    if (searchKeyword.value.trim()) {
      params.append('search', searchKeyword.value.trim())
    }

    const response = await fetch(`${API_BASE_URL}/articles/list?${params}`)
    const result = await response.json()

    if (result.code === 200) {
      const newArticles = result.data.list || []

      if (append) {
        articles.value.push(...newArticles)
      } else {
        articles.value = newArticles
      }

      pagination.value = { ...pagination.value, ...result.data.pagination }
    } else {
      message.error(result.msg || '获取文章列表失败')
    }
  } catch (error) {
    console.error('获取文章列表失败:', error)
    message.error('网络错误，请稍后重试')
  } finally {
    loading.value = false
    loadingMore.value = false
  }
}

// 处理筛选类型变化
const handleFilterChange = (type) => {
  filterType.value = type
  pagination.value.page = 1
  articles.value = [] // 清空当前文章列表
  fetchArticles(1)
}

// 处理分类变化
const handleCategoryChange = (categoryName) => {
  selectedCategory.value = categoryName
  pagination.value.page = 1
  articles.value = [] // 清空当前文章列表
  fetchArticles(1)
}

// 删除分类
const handleDeleteCategory = async (category) => {
  if (!hasAdminPermission.value) {
    message.error('您没有权限执行此操作')
    return
  }

  if (category.article_count > 0) {
    message.warning('该分类下还有文章，无法删除')
    return
  }

  // 确认删除
  Modal.confirm({
    title: '确认删除分类',
    content: `确定要删除分类"${category.name}"吗？此操作不可恢复。`,
    okText: '确定',
    cancelText: '取消',
    okType: 'danger',
    onOk: async () => {
      try {
        const response = await fetch(`${API_BASE_URL}/articles/categories/${category.id}`, {
          method: 'DELETE',
          headers: {
            Authorization: `Bearer ${getToken()}`
          }
        })

        const result = await response.json()

        if (result.code === 200) {
          message.success('分类删除成功')
          // 如果当前选中的分类被删除，清除选择
          if (selectedCategory.value === category.name) {
            selectedCategory.value = null
          }
          // 重新获取分类列表
          fetchCategories()
          // 重新获取文章列表
          fetchArticles(1)
        } else {
          message.error(result.msg || '删除分类失败')
        }
      } catch (error) {
        console.error('删除分类失败:', error)
        message.error('网络错误，请稍后重试')
      }
    }
  })
}

// 处理搜索
const handleSearch = () => {
  pagination.value.page = 1
  articles.value = [] // 清空当前文章列表
  fetchArticles(1)
}

// 加载更多文章
const loadMoreArticles = async () => {
  console.log('触发加载更多:', {
    loadingMore: loadingMore.value,
    hasNext: pagination.value.hasNext,
    currentPage: pagination.value.page,
    total: pagination.value.total
  })

  if (loadingMore.value || !pagination.value.hasNext) {
    console.log('跳过加载更多:', loadingMore.value ? '正在加载' : '没有更多数据')
    return
  }

  const nextPage = pagination.value.page + 1
  console.log('开始加载第', nextPage, '页')
  await fetchArticles(nextPage, true)
}

// 防抖函数
const debounce = (func, wait) => {
  let timeout
  return function executedFunction(...args) {
    const later = () => {
      clearTimeout(timeout)
      func(...args)
    }
    clearTimeout(timeout)
    timeout = setTimeout(later, wait)
  }
}

// 滚动容器引用
const scrollContainer = ref(null)

// 滚动监听
const handleScroll = debounce(() => {
  if (!scrollContainer.value) return

  const element = scrollContainer.value
  const scrollTop = element.scrollTop
  const clientHeight = element.clientHeight
  const scrollHeight = element.scrollHeight

  const distanceFromBottom = scrollHeight - (scrollTop + clientHeight)

  // 只在需要时输出调试信息
  if (distanceFromBottom <= 300) {
    console.log('接近底部:', {
      scrollTop: Math.round(scrollTop),
      clientHeight,
      scrollHeight,
      distanceFromBottom: Math.round(distanceFromBottom),
      hasNext: pagination.value.hasNext,
      loadingMore: loadingMore.value
    })
  }

  // 当滚动到距离底部100px时触发加载更多
  if (distanceFromBottom <= 100) {
    console.log('触发加载更多')
    loadMoreArticles()
  }
}, 150)

// 跳转到写文章页面
const handleWriteArticle = () => {
  if (!userStore.isAuthenticated) {
    message.info('请先登录后再发表文章')
    // 触发登录弹窗
    window.dispatchEvent(new CustomEvent('openLogin'))
    return
  }
  router.push('/articles/write')
}

// 跳转到文章详情页面
const handleArticleClick = (articleId) => {
  window.open(`/articles/${articleId}`, '_blank')
}

// 格式化数字
const formatNumber = (num) => {
  if (!num) return '0'
  if (num < 1000) return num.toString()
  if (num < 10000) return (num / 1000).toFixed(1) + 'k'
  return (num / 10000).toFixed(1) + 'w'
}

// 获取空状态文本
const getEmptyStateText = () => {
  if (searchKeyword.value) {
    return `没有找到与"${searchKeyword.value}"相关的文章`
  }
  if (selectedCategory.value) {
    return `"${selectedCategory.value}"分类下暂无文章`
  }
  return '快来发表第一篇文章吧'
}

// 页面加载时获取数据
onMounted(() => {
  fetchCategories()
  fetchArticles()

  // 等待DOM渲染完成后绑定滚动监听
  nextTick(() => {
    if (scrollContainer.value) {
      scrollContainer.value.addEventListener('scroll', handleScroll, { passive: true })
    } else {
      console.error('滚动容器未找到')
    }
  })
})

// 组件销毁时移除滚动监听
onBeforeUnmount(() => {
  if (scrollContainer.value) {
    scrollContainer.value.removeEventListener('scroll', handleScroll)
  }
})
</script>

<style scoped>
:deep(.ant-input-affix-wrapper) {
  border: none;
}

:deep(.ant-input-affix-wrapper:focus) {
  box-shadow: none;
}

:deep(.ant-input-affix-wrapper:hover) {
  box-shadow: none;
}

.articles-page {
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  height: 100%;
  overflow-y: scroll;
}

.page-header {
  background: linear-gradient(135deg, #ffffff 0%, #fafbfc 100%);
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.header-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 72px;
}

.nav-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #f8fafc;
  padding: 8px;
  border-radius: 16px;
}

.nav-tab {
  position: relative;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 12px;
  overflow: hidden;
}

.nav-tab::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  opacity: 0;
  transition: opacity 0.25s ease;
  border-radius: 12px;
}

.nav-tab:hover::before {
  opacity: 0.1;
}

.nav-tab.active::before {
  opacity: 1;
}

.tab-content {
  position: relative;
  z-index: 1;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 500;
  color: #64748b;
  transition: color 0.25s ease;
}

.nav-tab:hover .tab-content {
  color: #1e293b;
}

.nav-tab.active .tab-content {
  color: #ffffff;
  font-weight: 600;
}

.tab-icon {
  font-size: 16px;
  line-height: 1;
  filter: grayscale(0.3);
  transition: filter 0.25s ease;
}

.nav-tab.active .tab-icon {
  filter: grayscale(0);
}

.tab-text {
  font-weight: 500;
  letter-spacing: 0.025em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.write-btn {
  background: linear-gradient(135deg, #10b981, #059669);
  border: none;
  padding: 12px 24px;
  border-radius: 14px;
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.25);
  height: 48px;
  position: relative;
  overflow: hidden;
}

.write-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
  transition: left 0.5s ease;
}

.write-btn:hover::before {
  left: 100%;
}

.write-text {
  font-weight: 600;
  font-size: 15px;
  color: #ffffff;
  position: relative;
  z-index: 1;
}

.page-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px;
}

.content-container {
  display: flex;
  gap: 24px;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
}

.filter-card {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.2);
  position: sticky;
  top: 92px;
}

.filter-section {
  margin-bottom: 28px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.8), rgba(248, 250, 252, 0.6));
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(10px);
}

.filter-section:last-child {
  margin-bottom: 0;
}

.filter-section h4 {
  font-size: 16px;
  font-weight: 700;
  color: #1e293b;
  margin: 0 0 16px 0;
  letter-spacing: 0.025em;
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 8px;
  border-bottom: 2px solid rgba(59, 130, 246, 0.1);
}

.filter-section h4::before {
  content: '🔍';
  font-size: 18px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.1));
}

/* 分类筛选标题图标 */
.filter-section:nth-child(2) h4::before {
  content: '📂';
}

.search-container {
  position: relative;
}

.custom-search-input {
  border-radius: 8px;
  border: 2px solid #e2e8f0;
  transition: all 0.3s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
  overflow: hidden;
  background: #ffffff;
}

.custom-search-input:hover {
  border-color: #cbd5e1;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.06);
}

/* 自定义搜索框内部样式 */
.custom-search-input :deep(.ant-input) {
  border: none;
  background: transparent;
  font-size: 15px;
  color: #1e293b;
  font-weight: 500;
}

.custom-search-input :deep(.ant-input::placeholder) {
  color: #94a3b8;
  font-weight: 400;
  font-style: italic;
}

.custom-search-input :deep(.ant-input-search-button) {
  border: none;
  height: 100%;
  font-weight: 600;
  color: white;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
}

.custom-search-input :deep(.ant-input-search-button:active) {
  transform: translateX(0);
}

.custom-search-input :deep(.ant-input-clear-icon) {
  color: #94a3b8;
  font-size: 16px;
  transition: all 0.3s ease;
  margin-right: 8px;
}

.filter-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 16px 0;
}

.clear-btn {
  color: #ef4444;
  font-weight: 600;
  font-size: 13px;
  transition: all 0.3s ease;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.clear-btn:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.3);
}

.filter-scroll {
  padding-right: 6px;
}

.category-filters {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.filter-item {
  padding: 12px 18px;
  border-radius: 6px;
  font-size: 15px;
  color: #475569;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 2px solid transparent;
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(10px);
  position: relative;
  overflow: hidden;
}

.filter-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  opacity: 0;
  transition: opacity 0.3s ease;
  border-radius: 6px;
}

.filter-item:hover {
  background: rgba(255, 255, 255, 0.9);
  color: #1e293b;
  border-color: rgba(59, 130, 246, 0.2);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.08);
}

.filter-item:hover::before {
  opacity: 0.05;
}

.filter-item.active {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(139, 92, 246, 0.1));
  color: #1d4ed8;
  border-color: rgba(59, 130, 246, 0.3);
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.15);
  transform: translateY(-1px);
}

.filter-item.active::before {
  opacity: 0.1;
}

.filter-icon {
  font-size: 18px;
  margin-right: 10px;
  filter: grayscale(0.3);
  transition: filter 0.3s ease;
}

.filter-item.active .filter-icon {
  filter: grayscale(0);
}

.filter-text {
  font-weight: 500;
  flex: 1;
}

.filter-item .count {
  font-size: 13px;
  color: #94a3b8;
  font-weight: 500;
  margin-left: 8px;
}

.filter-item.active .count {
  color: #1d4ed8;
}

.category-name {
  flex: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
}

.delete-category-btn {
  opacity: 0;
  transition: all 0.3s ease;
  margin-left: 8px;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.filter-item:hover .delete-category-btn {
  opacity: 1;
  transform: scale(1.05);
}

.delete-category-btn:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.4);
  transform: scale(1.1);
}

.main-content {
  flex: 1;
  min-width: 0;
}

.empty-state {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  padding: 80px 40px;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.empty-illustration {
  font-size: 72px;
  color: #cbd5e1;
  margin-bottom: 20px;
  opacity: 0.8;
}

.empty-state h3 {
  font-size: 20px;
  color: #1e293b;
  margin: 0 0 12px 0;
  font-weight: 600;
}

.empty-state p {
  color: #64748b;
  margin: 0 0 24px 0;
  font-size: 15px;
}

.article-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.article-item {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  border-radius: 8px;
  padding: 24px;
  margin-bottom: 16px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  gap: 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.2);
  position: relative;
  overflow: hidden;
}

.article-item:hover {
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* 左侧强调条 */
.article-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, #3b82f6, #60a5fa, #93c5fd);
  opacity: 0;
  transition: opacity 0.2s;
}

.article-item:hover::before {
  opacity: 1;
}

.article-main {
  flex: 1;
  min-width: 0;
}

.article-title {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.4;
  margin: 0 0 16px 0;
  display: flex;
  align-items: center;
  gap: 12px;
  word-break: break-word;
  letter-spacing: -0.025em;
}

.recommend-badge {
  background: linear-gradient(135deg, #f59e0b, #f97316);
  color: #fff;
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 12px;
  font-weight: 600;
  flex-shrink: 0;
  letter-spacing: 0.025em;
  box-shadow: 0 2px 4px rgba(245, 158, 11, 0.3);
}

.article-abstract {
  font-size: 15px;
  color: #475569;
  line-height: 1.7;
  margin-bottom: 16px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-weight: 400;
}

.article-tags {
  margin-bottom: 20px;
}

.article-tag {
  border: 1px solid #e2e8f0;
  color: #475569;
  background: #f8fafc;
  font-size: 12px;
  margin-right: 10px;
  transition: all 0.2s;
  border-radius: 8px;
  padding: 4px 10px;
  font-weight: 500;
}

.article-tag:hover {
  color: #1d4ed8;
  border-color: #93c5fd;
  background: #eff6ff;
  transform: translateY(-1px);
}

.more-tags {
  font-size: 12px;
  color: #94a3b8;
  font-weight: 500;
}

.article-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 14px;
  color: #64748b;
  padding-top: 20px;
  margin-top: 12px;
  border-top: 1px solid #f1f5f9;
}

.author-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.author-avatar {
  background: #3b82f6;
  color: #fff;
  font-size: 12px;
}

.author-name {
  color: #374151;
  font-weight: 600;
  font-size: 14px;
}

.article-stats {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: 20px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #64748b;
  font-size: 13px;
  position: relative;
  font-weight: 500;
}

.stat-item:not(:last-child)::after {
  content: '·';
  color: #cbd5e1;
  margin-left: 8px;
  font-weight: bold;
}

.article-time {
  font-size: 13px;
  color: #64748b;
  font-weight: 500;
}

.article-cover {
  width: 140px;
  flex-shrink: 0;
  border-radius: 12px;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.article-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s;
}

/* 加载更多状态样式 */
.load-more-status {
  margin-top: 32px;
  text-align: center;
  padding: 24px;
}

.loading-more {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: #3b82f6;
  font-size: 15px;
  font-weight: 500;
}

.no-more {
  color: #64748b;
  font-size: 15px;
  font-weight: 500;
}

.total-info {
  margin-top: 10px;
  font-size: 13px;
  color: #94a3b8;
  font-weight: 400;
}

/* 骨架屏布局 */
.skeleton-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* 响应式设计 */
@media (max-width: 1024px) {
  .content-container {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
  }

  .filter-card {
    position: static;
  }
}

/* 自定义滚动条 */
.articles-page::-webkit-scrollbar {
  width: 8px;
}

.articles-page::-webkit-scrollbar-track {
  background: transparent;
}

.articles-page::-webkit-scrollbar-thumb {
  background: rgba(203, 213, 225, 0.6);
  border-radius: 4px;
}

.articles-page::-webkit-scrollbar-thumb:hover {
  background: rgba(203, 213, 225, 0.8);
}
</style>
